<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript">
      window.onload= function()
      {
        var aBtn = document.getElementsByTagName('input');

        for(var i=0 ; i < aBtn.length ;i++)
        {
            (function(i){
              aBtn[i].onclick=function(){
                alert(i);
              };
            })(i);
        }
      };
    </script>
  </head>
  <body>
    <input type="button" name="" value="1">
    <input type="button" name="" value="2">
    <input type="button" name="" value="3">
  </body>
</html>
